// +----------------------------------------------------------------------
// | BossHongshi [鸿时互娱管理系统]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.hongshihuyu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wgh
// +----------------------------------------------------------------------
const fly=require("flyio")
module.exports = class extends think.cmswing.center {
  
//授权注册
  async authAction() {
		const id = this.get('id') || null;
		console.log("id -----------:"+id);
		var array = id.split('&');
		console.log("array[0] -----------:"+array[0]);
		console.log("array[1] -----------:"+array[1]);
		
		fly.config.timeout=10000;
		fly.config.parseJson=true;
		fly.interceptors.response.use(
			    (response) => {
			        //只将请求结果的data字段返回
			        return response.data
			    },
			    (err) => {
			        //发生网络错误后会走到这里
			        //return Promise.resolve("ssss")
			    }
		)
		
		var url = 'http://47.97.119.70:5166/GameSupport/dn?cmd=getPlayerByUid&uid='+array[1]+'&sign=password';
		
		console.log('查询玩家信息--url---------:'+url);
	    let ret = await fly.get(url).catch(() => false);
		console.log('查询玩家信息 purl ret------------------:'+ret);
		let retdata = (ret === false?null:JSON.parse(ret));
		
//		if(retdata!=null&&retdata.data.result==0){
//			pdata = retdata.data.info;
//			pdata.headimgurl = (pdata.headimgurl.indexOf('defaultHead.jpg')!= -1)?'/static/mobile/img/defaultHead.jpg':pdata.headimgurl;
//		}
		
		//const userInfo = await this.model('member').find(this.user.uid);
		//this.assign('proxy_id', userInfo.proxy_id);
		this.assign('beinvInfo', retdata.data.info);
		
		var userInfo = await this.model('member').where({proxy_id:array[0]}).find();
		var proxyInfo = {
				uid:userInfo.game_id,
				headimgurl :(userInfo.avatar.indexOf('defaultHead.jpg')!= -1)?'/static/mobile/img/defaultHead.jpg':userInfo.avatar,
				nickname :userInfo.nick_name,
				proxy_id:userInfo.proxy_id
		}
		
		this.assign('proxyInfo', proxyInfo);
		
	    this.meta_title = '授权注册';
	    // 判断浏览客户端
	    if (this.isMobile) {
	      if (this.isAjax('get')) {
	        return this.json(data);
	      } else {
	        this.active = 'center/agent/index';
	        return this.display(this.mtpl());
	      }
	    } else {
	      return this.display();
	    }
  }
};
